﻿using System.Reflection;

namespace Borg
{
    internal class UnplugPlugsTask : Task<ExtensionInfo>
    {
        private readonly ExtensionInfo _ei;

        public override string Name
        {
            get
            {
                return _ei == null
                    ? string.Format("UnplugPlugs({0})", obj.Name)
                    : string.Format("UnplugPlugs({0}, {1})", obj.Name, _ei.Name);
            }
        }

        public UnplugPlugsTask(ExtensionInfo obj, ExtensionInfo ei,
            uint taskGroupId, Assembly initiator)
            : base(obj, taskGroupId, initiator)
        {
            _ei = ei;
        }

        public override void Execute()
        {
            if (_ei == null)
                obj.InternalUnplugPlugs(initiator, false);
            else
                obj.InternalUnplugPlugs(_ei, initiator, false);
        }

        public override string ToString()
        {
            return _ei == null
                ? string.Format("{0}: {1}.InternalUnplugPlugs()", taskGroupId, obj)
                : string.Format("{0}: {1}.InternalUnplugPlugs({2})", taskGroupId, obj, _ei);
        }
    }
}

